package logic

import (
	"context"
	"market/marketrpc/internal/svc"
	"market/marketrpc/marketrpc"
	"market/model/mysql"
	"market/model/redis"

	"github.com/zeromicro/go-zero/core/logx"
)

type PorductLikeLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPorductLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PorductLikeLogic {
	return &PorductLikeLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PorductLikeLogic) PorductLike(in *marketrpc.PorductLikeRequest) (*marketrpc.PorductLikeResponse, error) {
	// todo: add your logic here and delete this line
	var shop mysql.Products
	mysql.DB.Debug().Where("id =?", in.Id).Find(&shop)

	redis.Client.ZIncrBy("productilkel", 1, shop.Name)
	return &marketrpc.PorductLikeResponse{Id: int64(shop.ID)}, nil
}
